package com.ruoyi.web.controller.system;

import cn.hutool.core.comparator.CompareUtil;
import com.ruoyi.business.domain.TUserOptLog;
import com.ruoyi.business.service.ITUserOptLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController extends BaseController {
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;

    @Autowired
    private ITUserOptLogService tUserOptLogService;

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user) {
        /*if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }*/
        String msg = registerService.register(user);

        TUserOptLog tUserOptLog = new TUserOptLog()
                .setOptDesc("报名注册")
                .setOptTime(DateUtils.getNowDate())
                .setFromUserid(user.getUsername())
                .setFromUsername(user.getNickName())
                .setFromRolename("")
                .setToUserid(user.getUsername())
                .setToUsername(user.getNickName());
        tUserOptLogService.save(tUserOptLog);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
